﻿using ProductMonitor.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace ProductMonitor.ViewModels
{
    public class MainWindowVM : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler? PropertyChanged;
        private UserControl _MonitorUC;


        public MainWindowVM()
        {
            HuanJingList = new List<HuanJingModel>();
            HuanJingList.Add(new HuanJingModel { ItemName = "光照(LUX)", ItemValue = 100 });
            HuanJingList.Add(new HuanJingModel { ItemName = "噪音(db)", ItemValue = 100 });
            HuanJingList.Add(new HuanJingModel { ItemName = "温度(C)", ItemValue = 100 });
            HuanJingList.Add(new HuanJingModel { ItemName = "湿度(%)", ItemValue = 100 });
            HuanJingList.Add(new HuanJingModel { ItemName = "PM2.5(M)", ItemValue = 100 });
            HuanJingList.Add(new HuanJingModel { ItemName = "硫化氢(PPM)", ItemValue = 100 });
            HuanJingList.Add(new HuanJingModel { ItemName = "氮气(LUX)", ItemValue = 100 });

            AlarmList = new List<AlarmModel>();
            AlarmList.Add(new AlarmModel { Num = "01", Msg = "设备温度过高", Time = "2024-10-09", Duration = 7 });
            AlarmList.Add(new AlarmModel { Num = "02", Msg = "设备温度过高", Time = "2024-10-09", Duration = 7 });
            AlarmList.Add(new AlarmModel { Num = "03", Msg = "设备温度过高", Time = "2024-10-09", Duration = 10 });
            AlarmList.Add(new AlarmModel { Num = "04", Msg = "设备温度过高", Time = "2024-10-09", Duration = 19 });
            AlarmList.Add(new AlarmModel { Num = "05", Msg = "设备温度过高", Time = "2024-10-09", Duration = 22 });
            AlarmList.Add(new AlarmModel { Num = "01", Msg = "设备温度过高", Time = "2024-10-09", Duration = 7 });
            AlarmList.Add(new AlarmModel { Num = "02", Msg = "设备温度过高", Time = "2024-10-09", Duration = 7 });
            AlarmList.Add(new AlarmModel { Num = "03", Msg = "设备温度过高", Time = "2024-10-09", Duration = 10 });
            AlarmList.Add(new AlarmModel { Num = "04", Msg = "设备温度过高", Time = "2024-10-09", Duration = 19 });
            AlarmList.Add(new AlarmModel { Num = "05", Msg = "设备温度过高", Time = "2024-10-09", Duration = 22 });
            AlarmList.Add(new AlarmModel { Num = "01", Msg = "设备温度过高", Time = "2024-10-09", Duration = 7 });
            AlarmList.Add(new AlarmModel { Num = "02", Msg = "设备温度过高", Time = "2024-10-09", Duration = 7 });
            AlarmList.Add(new AlarmModel { Num = "03", Msg = "设备温度过高", Time = "2024-10-09", Duration = 10 });
            AlarmList.Add(new AlarmModel { Num = "04", Msg = "设备温度过高", Time = "2024-10-09", Duration = 19 });
            AlarmList.Add(new AlarmModel { Num = "05", Msg = "设备温度过高", Time = "2024-10-09", Duration = 22 });


            //初始化雷达数据
            RaderList = new List<RaderModel>();
            RaderList.Add(new Model.RaderModel { ItemName = "排烟风机", Value = 90 });
            RaderList.Add(new Model.RaderModel { ItemName = "客梯", Value = 30.00 });
            RaderList.Add(new Model.RaderModel { ItemName = "供水机", Value = 34.89 });
            RaderList.Add(new Model.RaderModel { ItemName = "喷淋水泵", Value = 69.59 });
            RaderList.Add(new Model.RaderModel { ItemName = "温压设备", Value = 20 });


            StaffList = new List<StaffOutWorkModel>();
            StaffList.Add(new Model.StaffOutWorkModel { StaffName = "张三", Position = "技术员", OutCount = 10 });
            StaffList.Add(new Model.StaffOutWorkModel { StaffName = "小明", Position = "技术员", OutCount = 50 });
            StaffList.Add(new Model.StaffOutWorkModel { StaffName = "李四", Position = "技术员", OutCount = 20 });
            StaffList.Add(new Model.StaffOutWorkModel { StaffName = "小陈", Position = "技术员", OutCount = 10 });
            StaffList.Add(new Model.StaffOutWorkModel { StaffName = "二哇", Position = "技术员", OutCount = 10 });

            WorkShopList = new List<WorkShopModel>();
            WorkShopList.Add(new WorkShopModel { WorkShopName = "贴片车间", WorkingCount = 32, WaitCount = 8, FaultCount = 4, StopCount = 8, });
            WorkShopList.Add(new WorkShopModel { WorkShopName = "封装车间", WorkingCount = 35, WaitCount = 8, FaultCount = 4, StopCount = 8, });
            WorkShopList.Add(new WorkShopModel { WorkShopName = "焊接车间", WorkingCount = 36, WaitCount = 8, FaultCount = 4, StopCount = 8, });
            WorkShopList.Add(new WorkShopModel { WorkShopName = "贴片车间2", WorkingCount = 33, WaitCount = 8, FaultCount = 4, StopCount = 8, });

            MachineList = new List<MachineModel>();
            Random random = new Random();

            for (int i = 0; i < 20; i++)
            {
                int planCount = random.Next(100, 100);
                int complet = random.Next(0, planCount);

                MachineList.Add(new MachineModel
                {
                    MachineName = "焊接机-" + (i + 1),
                    FinishedCount = complet,
                    PlanCount = planCount,
                    OrderNo = "H1234567890",
                    Status = "作业中"

                });
            }

        }

        public UserControl MonitorUC
        {
            get
            {
                if (_MonitorUC == null)
                {
                    _MonitorUC = new UserControls.MonitorUC();
                }
                return _MonitorUC;
            }
            set
            {
                _MonitorUC = value;

                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("MonitorUC"));
                }
            }
        }

        #region 时间
        /// <summary>
        /// 时间 格式 小时:分钟
        /// </summary>
        public string TimeStr
        {

            get
            {
                return DateTime.Now.ToString("HH:mm");
            }
        }

        /// <summary>
        /// 时间 格式 小时:分钟
        /// </summary>
        public string DateStr
        {

            get
            {
                return DateTime.Now.ToString("yyyy-MM-dd");
            }
        }

        /// <summary>
        /// 时间 格式 小时:分钟
        /// </summary>
        public string WeekStr
        {

            get
            {
                int day = (int)DateTime.Now.DayOfWeek;
                string[] week = new string[7] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
                return week[day];
            }
        }
        #endregion

        #region 计数
        private string _MachineCount = "0298";

        public string MachineCount
        {
            get { return _MachineCount; }
            set
            {
                _MachineCount = value;

                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("MachineCount"));
                }
            }
        }

        private string _ProductCount = "1643";

        public string ProductCount
        {
            get { return _ProductCount; }
            set
            {
                _ProductCount = value;

                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("ProductCount"));
                }
            }
        }


        private string _NgCount = "1643";

        public string NgCount
        {
            get { return _NgCount; }
            set
            {
                _NgCount = value;

                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("NgCount"));
                }
            }
        }
        #endregion

        #region 环境数据
        private List<HuanJingModel> _HuanJingList;

        public List<HuanJingModel> HuanJingList
        {
            get { return _HuanJingList; }
            set
            {
                _HuanJingList = value;

                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("HuanJingList"));
                }

            }
        }

        #endregion
        #region 报警
        private List<AlarmModel> _AlarmList;




        public List<AlarmModel> AlarmList
        {
            get { return _AlarmList; }
            set
            {
                _AlarmList = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("AlarmList"));
                }
            }
        }

        #endregion


        private List<DeviceModel> _DeviceModel;

        public List<DeviceModel> DeviceModelroperty
        {
            get { return _DeviceModel; }
            set
            {
                _DeviceModel = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("DeviceModelroperty"));
                }
            }
        }


        private List<RaderModel> _RaderModel;

        public List<RaderModel> RaderList
        {
            get { return _RaderModel; }
            set
            {
                _RaderModel = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("RaderList"));
                }
            }
        }


        private List<StaffOutWorkModel> _StaffList;

        public List<StaffOutWorkModel> StaffList
        {
            get { return _StaffList; }
            set
            {
                _StaffList = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("StaffList"));
                }
            }
        }

        #region 车间属性
        private List<WorkShopModel> _WorkShopList;

        public List<WorkShopModel> WorkShopList
        {
            get { return _WorkShopList; }
            set { _WorkShopList = value; }
        }

        #endregion

        #region 机台属性
        private List<MachineModel> _MachineList;

        public List<MachineModel> MachineList
        {
            get { return _MachineList; }
            set
            {
                _MachineList = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("MachineListx`"));
                }
            }
        }

        #endregion
    }
}
